<?php

namespace Acme\MailerBundle;

use Symfony\Component\Templating\EngineInterface;

use Acme\UserBundle\Entity\CmUser;
use Acme\ContestBundle\Entity\CtInfo;

class MailManager
{
    protected $mailer;

    protected $templating;

    public function __construct(\Swift_Mailer $mailer, EngineInterface $templating)
    {
        $this->mailer = $mailer;
        $this->templating = $templating;
    }

	public function emailValid(CmUser $user)
    {
        $message = \Swift_Message::newInstance()
    		->setSubject('辽宁大学生创新创业大赛平台邮箱验证提醒')
    		->setFrom(array('1400642406@qq.com' => '辽宁大学生创新创业大赛平台'))
    		->setTo(array($user->getEmail() => $user->getUsername()))
    		->setBody($this->templating->render('AcmeMailerBundle:MailView:emailValid.html.twig', array('user' => $user)), 'text/html');
    	$this->mailer->send($message);
    }
    
    public function userCreate(CmUser $user, $plaintext_password)
    {
    	$message = \Swift_Message::newInstance()
    	->setSubject('辽宁大学生创新创业大赛平台用户创建提醒')
    	->setFrom(array('1400642406@qq.com' => '辽宁大学生创新创业大赛平台'))
    	->setTo(array($user->getEmail() => $user->getUsername()))
    	->setBody($this->templating->render('AcmeMailerBundle:MailView:userCreate.html.twig', array('user' => $user, 'plaintext_password' => $plaintext_password)), 'text/html');
    	$this->mailer->send($message);
    }
    
    public function contestCreate(CtInfo $contest)
    {
    	$message = \Swift_Message::newInstance()
    	->setSubject('辽宁大学生创新创业大赛平台竞赛创建提醒')
    	->setFrom(array('1400642406@qq.com' => '辽宁大学生创新创业大赛平台'))
    	->setTo(array($contest->getApplyByInfo()->getEmail() => $contest->getApplyByInfo()->getUsername()))
    	->setBody($this->templating->render('AcmeMailerBundle:MailView:contestCreate.html.twig', array('contest' => $contest)), 'text/html');
    	$this->mailer->send($message);
    }
}